#!/usr/bin/env drgn

from drgn.helpers.linux.fs import for_each_mount, d_path
from drgn.helpers.linux.pid import for_each_task
import sys

def get_mountinfo(task):

    mounts = task.nsproxy.mnt_ns
    for mnt in for_each_mount(mounts):
        devname = mnt.mnt_devname
        fstype = mnt.mnt.mnt_sb.s_type.name
        mntpt = d_path(
            mnt.mnt_parent.mnt.address_of_(), mnt.mnt_mountpoint
        )

        filetype = fstype.string_().decode("utf-8")
        dev = devname.string_().decode("utf-8")
        mount_pt = mntpt.decode("utf-8")

        if "nfs" in filetype:
            pid = task.pid.value_()
            comm = task.comm.string_().decode("utf-8")
            print(f"task pid: {pid}, comm: {comm}")
            print(f"dev: {dev}, fstype: {filetype}, mount point: {mount_pt}")
            

def main():
   for task in for_each_task(prog):
        get_mountinfo(task) 
    

if __name__ == '__main__':
    main()
